/*
* berton
*/
package com.pitop.material.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import com.pitop.material.api.MaterialFeignApi;
import com.pitop.core.exceptions.MaterialException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.material.entity.Material;


/**
 * 供应料材
 * @author berton
 */
@Service("materialSVImpl")
@Slf4j
public class MaterialSVImpl {

    @Autowired
    private MaterialFeignApi materialFeignApi;

    /**
     * 加载一个对象Material
     * @param id * @param code 编码* @param suppierCode 供应商编码
     * @return Material
     */
    public Material load(java.lang.Long id,java.lang.String code,java.lang.String suppierCode) {
        if(id==null&&code==null&&suppierCode==null){
            throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialFeignApi.load(id,code,suppierCode);
    }
    /**
     * 加载一个对象Material 通过id
     * @param id 
     * @return Material
     */
    public Material loadById(java.lang.Long id) {
        if(id==null){
            throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialFeignApi.loadById(id);
    }

    /**
     * 加载一个对象Material 通过code
     * @param code 编码
     * @return Material
     */
    public Material loadByCode(java.lang.String code) {
        if(code==null){
            throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialFeignApi.loadByCode(code);
    }

    /**
     * 加载一个对象Material 通过suppierCode
     * @param suppierCode 供应商编码
     * @return Material
     */
    public Material loadBySuppierCode(java.lang.String suppierCode) {
        if(suppierCode==null){
            throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialFeignApi.loadBySuppierCode(suppierCode);
    }


    /**
     * 删除对象Material
     * @param id * @param code 编码* @param suppierCode 供应商编码
     * @return Material
     */
    
    public void delete(java.lang.Long id,java.lang.String code,java.lang.String suppierCode) {
        if(id==null&&code==null&&suppierCode==null){
            throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        materialFeignApi.delete(id,code,suppierCode);
    }



    /**
     * 查询Material分页
     *
     * @param material  对象
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<Material>
     */
    public List<Material> list(Material material, int curPage,int pageSize) {
        return materialFeignApi.list(material, curPage,pageSize);
    }

    /**
     * 查询Material分页
     *
     * @param id  * @param code  编码* @param suppierCode  供应商编码
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<Material>
     */
    public List<Material> list(java.lang.Long id,java.lang.String code,java.lang.String suppierCode,int curPage, int pageSize) {
        if (curPage < 0) {
           curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        Material material=new Material();
        material.setId(id);
        material.setCode(code);
        material.setSuppierCode(suppierCode);

        return materialFeignApi.list(material,curPage,pageSize);
    }


    public int count(java.lang.Long id,java.lang.String code,java.lang.String suppierCode) {
        return materialFeignApi.count(id,code,suppierCode);
    }


    public int count(Material material) {
        return materialFeignApi.count(material);
    }


    /**
     * 保存
     *
     * @param material 实体
     * @throws BaseException
     */
    public void save(Material material) {
        if(material==null){ throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        materialFeignApi.build(material);
    }

    /**
     * 更新
     *
     * @param material 实体
     * @throws BaseException
     */
    public void modify(Material material) {
        if(material==null){ throw new MaterialException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        materialFeignApi.modify(material);
    }

}
